import {
  Entity, PrimaryGeneratedColumn, Column, BeforeInsert
} from 'typeorm';

@Entity('task')
export class TaskEntity {
  @PrimaryGeneratedColumn({
    comment: '主键id',
    name: 'id',
    type: 'int',
  })
  id: number;

  @Column('varchar', {
    nullable: false,
    primary: true,
    generated: 'uuid',
    length: 50,
    name: 'uuid',
    comment: 'uuid',
  })
  uuid: string;

  @Column('varchar', {
    nullable: false,
    length: 50,
    name: 'name',
    comment: '任务名',
  })
  name: string;

  @Column('enum', {
    nullable: false,
    default: 1,
    enum: [1, 2, 3],
    name: 'group',
    comment: '任务组',
  })
  group: number;

  @Column('varchar', {
    nullable: false,
    length: 50,
    name: 'rules',
    comment: '定时规则',
  })
  rules: string;

  @Column('enum', {
    nullable: false,
    enum: [0, 1],
    default: 0,
    name: 'status',
    comment: '启用状态'
  })
  status: number;

  @Column('varchar', {
    nullable: true,
    length: 512,
    name: 'description',
    comment: '任务描述'
  })
  description: string;

  @Column('timestamp', {
    nullable: false,
    default: () => 'CURRENT_TIMESTAMP',
    name: 'createdAt',
    comment: '创建时间',
  })
  createdAt: Date;

  @Column('timestamp', {
    nullable: false,
    default: () => 'CURRENT_TIMESTAMP',
    name: 'updatedAt',
    comment: '最后更新时间',
  })
  updatedAt: Date;
}